var x
x = $(document);
x.ready(initialize);


function initialize(){
	var input = $('input');
	input.keypress(
	function(e){
		if (e.which==13) {
			SearchPlace();
		}
	});
	
}

function SearchPlace(){
	var value = $('input').attr('value');
	var method = 'SearchPlaceByName';
	$.getJSON('./php/method.php',{q:value,s:method},Process);
}


function Process(data){
	var PlaceList = $('#PlaceList');
	PlaceList.html('');
	for(i=0;i<data.length;i++){
		var cod_place = '<div id="'+data[i].cod_place+'" data-role="collapsible" data-collapsed="true">';
		var name = '<h3>'+data[i].name+'</h3>';
		var phone = 'Phone: '+data[i].phone+'<br />';
		var website = 'Website: <a href="'+data[i].website+'">'+data[i].website+ '</a> <br />';
		var email = 'Email: '+data[i].email+'<br />';
		var description = 'Description: '+data[i].description+'<br />';
		var delivery;
		if (data[i].delivery == 0){
			delivery = 'Delivery: No'+'<br />';
		}
		else 
			delivery = 'Delivery: Yes'+' <br />';
		var cierre = '</div>';
		PlaceList.append(cod_place + name + phone + website + email + description + delivery + cierre).trigger('create');
	}
}